﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Web;
using System.Web.Mvc;
using VCC.Model;
using VCC.Lib.Paging;
using VCC.Site.ViewModels;
using VCC.Lib.Common;
namespace VCC.Site.Controllers
{
    public class AdJobController : Controller
    {
        //
        // GET: /AdJob/
        ChoVietDataContext eDataContext = new ChoVietDataContext();
        public ActionResult Index()
        {
            return View();
        }
       
        public ActionResult TabJobs(int Id)
        {
            ChoVietDataContext eDataContext = new ChoVietDataContext();
            TabGetJobModel model = new TabGetJobModel();
            DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
            model.Category = eDataContext.Categories.Where(e => e.ID == Id).FirstOrDefault();
            int Boxsize = !string.IsNullOrEmpty(Request["Boxsize"]) ? int.Parse(Request["Boxsize"].ToString()) : 8;
            model.Ads = eDataContext.Ads.Where(e=> e.PublishYN == true && e.Status != 0 && e.StartDate <= today &&
                                          e.Status != byte.Parse(AdStatus.Deleted.GetHashCode().ToString()) &&  
                                         (e.CatID == Id || e.Category.ParentID == Id) )
                                        .OrderBy(string.Format("{0} {1}", "SortDate", "DESC"))
                                         .OrderBy(string.Format("{0} {1}", "VIPTypeID", "ASC"))
                                         .ToPagedList(0, Boxsize);
            
            return View(model);
        }

        public ActionResult TabJobGetCategory(int id)
        {
            TabJobGetCategoryModel model = new TabJobGetCategoryModel();
            model.Categories = eDataContext.Categories.Where(e => e.PubYN == true && e.ParentID == id).OrderBy("Priority", "ASC").ToList();
            return View(model);
        }
    }
}
